/************************************************************************************

Class Name	:	Main.class
Description	:	Used to place the buttons in the Grid Layout
Author		:	W.S.V.K.Koggala <v.koggala@gmail.com>

*************************************************************************************/

package com.androidcal.calculator;

	import android.widget.*;
	import android.content.*;
	import android.view.*;
import android.view.View.OnClickListener;
//import android.view.View.OnFocusChangeListener;

	public class KeypadAdapter extends BaseAdapter{
	  private Context context;
	  private OnClickListener onButtonClick;
	//private OnFocusChangeListener onFocus;

		
		
	  public KeypadAdapter(Context con) {
	    context = con;
	  }
	  
	  public void setOnButtonClickListener(OnClickListener listener) {
			onButtonClick = listener;
		}


	  public int getCount() {
	    return calButtons.length;
	  }

	  public Object getItem(int position) {
	    return calButtons[position];
	  }

	  public long getItemId(int position) {
	    return 0;
	  }

	// creating a new ButtonView for each item referenced by the Adapter
	 //provide keypad button instances to the grid view 
	public View getView(int position, View convertView, ViewGroup parent) {
	  Button btn;
	  if (convertView == null) { 
	    btn = new Button(context);
	    KeypadButton keypadButton = calButtons[position];
	    if (keypadButton != KeypadButton.NY)
            btn.setOnClickListener(onButtonClick);
	    

	  // if(keypadButton == KeypadButton.ONE)
	    	btn.setBackgroundResource(R.drawable.keypadclear);

	   
	
	    // Set CalculatorButton enumeration as tag of the button 
	    btn.setTag(keypadButton);
	  } 
	  else {
	    btn = (Button) convertView;
	  }

	  btn.setText(calButtons[position].getText());
	  return btn;
	}

	// Create the keypad buttons array with CalculatorButton values
	 private KeypadButton[] calButtons = { KeypadButton.HELP, KeypadButton.ENT,KeypadButton.SPACE, KeypadButton.TRANSPOSE, KeypadButton.BINARY,
	 KeypadButton.OCTAL, KeypadButton.HEXADECIMAL, KeypadButton.SOLVE, KeypadButton.EQUATIONS,KeypadButton.SQUARE, KeypadButton.E, KeypadButton.LOG,
	 KeypadButton.LN, KeypadButton.POWER,
	 KeypadButton.DELETE, KeypadButton.AC, KeypadButton.CBRT,KeypadButton.SQRT, KeypadButton.RADIAN,
	 KeypadButton.DEGREE, KeypadButton.PI,
	 KeypadButton.SEVEN,KeypadButton.EIGHT, KeypadButton.NINE, KeypadButton.DIVIDE,KeypadButton.SIN,
	 KeypadButton.COS, KeypadButton.TAN,
	 KeypadButton.FOUR, KeypadButton.FIVE,KeypadButton.SIX, KeypadButton.MULTIPLY, KeypadButton.SINH,
	 KeypadButton.COSH, KeypadButton.TANH,
	 KeypadButton.ONE, KeypadButton.TWO, KeypadButton.THREE,KeypadButton.MINUS, KeypadButton.ASIN,KeypadButton.ACOS, KeypadButton.ATAN, 
	 KeypadButton.ZERO, KeypadButton.DOT,KeypadButton.SIGN,KeypadButton.PLUS, KeypadButton.EQUALS,KeypadButton.BASIC, KeypadButton.MATRIX,
	 KeypadButton.MATA,KeypadButton.MATB,KeypadButton.MATRIXADD,KeypadButton.MATMUL,KeypadButton.INVERSE,KeypadButton.DETERMINANT,KeypadButton.ADJOINT
	 
	 };



	//	Log.d("focus ", "status : " + hasFocus);
	


}
